import { app } from 'electron'
import { configTypes } from '@globalTypes/global'
import { StorageTool } from '../composables/StorageTool'

// 设置开机启动
export const setAutoOpenStatus = (autoOpen?: boolean) => {
  if (autoOpen === undefined) {
    const storageTool = new StorageTool('config')
    const configStr = storageTool.getStorageStr('timer')
    if (configStr != null && configStr != 'undefined') {
      const config = JSON.parse(configStr) as configTypes.Config
      autoOpen = config.autoOpen
    }
  }
  if (app.isPackaged) {
    if (autoOpen) {
      // 开机启动
      app.setLoginItemSettings({
        openAtLogin: true
      })
    } else {
      // 关闭开机启动
      app.setLoginItemSettings({
        openAtLogin: false
      })
    }
  }
}
